

#include "Sort.hpp"


void TestOP()
{
	srand((uint32_t)time(0));
	const int N = 10000000;
	int* a0 = (int*)malloc(sizeof(int) * N);
	int* a1 = (int*)malloc(sizeof(int) * N);
	int* a2 = (int*)malloc(sizeof(int) * N);
	int* a3 = (int*)malloc(sizeof(int) * N);
	int* a4 = (int*)malloc(sizeof(int) * N);
	int* a5 = (int*)malloc(sizeof(int) * N);
	int* a6 = (int*)malloc(sizeof(int) * N);
	
	for (int i = 0; i < N; ++i)
	{
		a0[i] = rand() + 1;
		a1[i] = a0[i];
		a2[i] = a0[i];
		a3[i] = a0[i];
		a4[i] = a0[i];
		a5[i] = a0[i];
		a6[i] = a0[i];
	}

	//int begin0 = clock();
	//BubbleSort(a1, N);
	//int end0 = clock();
	
	//int begin1 = clock();
	//InsertSort(a1, N);
	//int end1 = clock();
	
	int begin2 = clock();
	ShellSort(a2, N);
	int end2 = clock();
	
	//int begin3 = clock();
	//SelectSort(a3, N);
	//int end3 = clock();
	
	int begin4 = clock();
	HeapSort(a4, N);
	int end4 = clock();
	
	int begin5 = clock();
	QuickSort(a5, 0, N - 1);
	// QuickSort(a5, N);
	int end5 = clock();
	
	int begin6 = clock();
	MergeSort(a6, N);
	int end6 = clock();
	
	//printf("BubbleSort: %d\n", end0 - begin0);
	//printf("InsertSort: %d\n", end1 - begin1);
	printf("ShellSort: %d\n", end2 - begin2);
	//printf("SelectSort: %d\n", end3 - begin3);
	printf("HeapSort: %d\n", end4 - begin4);
	printf("QuickSort: %d\n", end5 - begin5);
	printf("MergeSort: %d\n", end6 - begin6);
	
	free(a0);
	free(a1);
	free(a2);
	free(a3);
	free(a4);
	free(a5);
	free(a6);
}


void Test_BubbleSort()
{
	int a[] = { 3, 5, 2, 10, 7, 5, 4, 11, 55, 33 };
	BubbleSort(a, sizeof a / sizeof a[0]);
	PrintArray(a, sizeof a / sizeof a[0]);
}

void Test_InsertSort()
{
	int a[] = { 3, 5, 2, 10, 7, 5, 4, 11, 55, 33 };
	InsertSort(a, sizeof a / sizeof a[0]);
	PrintArray(a, sizeof a / sizeof a[0]);
}

void Test_ShellSort()
{
	int a[] = { 3, 5, 2, 10, 7, 5, 4, 11, 55, 33 };
	ShellSort(a, sizeof a / sizeof a[0]);
	PrintArray(a, sizeof a / sizeof a[0]);
}

void Test_SelectSort()
{
	int a[] = { 55, 2, 3, 3, 5, 2, 10, 7, 5, 4, 11, 55, 33 };
	SelectSort(a, sizeof a / sizeof a[0]);
	PrintArray(a, sizeof a / sizeof a[0]);
}

void Test_HeapSort()
{
	int a[] = { 55, 2, 3, 3, 5, 2, 10, 7, 5, 4, 11, 55, 33 };
	HeapSort(a, sizeof a / sizeof a[0]);
	PrintArray(a, sizeof a / sizeof a[0]);
}

void Test_QuickSort()
{
	//int a[] = { 55, 2, 3, 3, 5, 2, 10, 7, 5, 4, 11, 55, 33 };
	int a[] = { 6, 1, 2, 6, 7, 9, 3, 4, 5, 6, 10, 8 };
	//QuickSort(a, 0, (sizeof a / sizeof a[0]) - 1);
	QuickSortNonRecursion(a, 0, (sizeof a / sizeof a[0]) - 1);
	PrintArray(a, sizeof a / sizeof a[0]);
}

void Test_MergeSort()
{
	int a[] = { 55, 2, 3, 3, 5, 2, 10, 7, 5, 4, 11, 55, 33 };
	//int a[] = { 6, 1, 2, 6, 7, 9, 3, 4, 5, 6, 10, 8 };
	//int a[] = { 6, 1, 2, 9, 3, 4, 10, 8 };
	//MergeSort(a, (sizeof a / sizeof a[0]));
	MergeSortNonRecursion(a, (sizeof a / sizeof a[0]));
	PrintArray(a, sizeof a / sizeof a[0]);
}


int main()
{
	//TestOP();
	
	//Test_InsertSort();
	//Test_BubbleSort();
	//Test_ShellSort();
	//Test_SelectSort();
	//Test_HeapSort();
	//Test_QuickSort();
	Test_MergeSort();
	
	return 0;
}